package phaseframe

import (
	confv1beta1 "gopkg.openfuyao.cn/bkecommon/cluster/api/v1beta1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	ctrl "sigs.k8s.io/controller-runtime"

	bkev1beta1 "gopkg.openfuyao.cn/cluster-api-provider-bke/api/v1beta1"
)

// Phase is the interface of a phase
type Phase interface {
	// Name returns the name of the phase
	Name() confv1beta1.BKEClusterPhase

	// Execute executes the phase
	Execute() (ctrl.Result, error)

	// ExecutePreHook executes the pre-hook of the phase
	ExecutePreHook() error

	// ExecutePostHook executes the post-hook of the phase
	ExecutePostHook(err error) error

	// NeedExecute returns whether the phase needs to be executed, run in webhook
	NeedExecute(old *bkev1beta1.BKECluster, new *bkev1beta1.BKECluster) (needExecute bool)

	//RegisterPreHooks is used to register a custom pre hook function
	RegisterPreHooks(hooks ...func(p Phase) error)

	// RegisterPostHooks is used to register a custom post hook function
	RegisterPostHooks(hook ...func(p Phase, err error) error)

	// Report reports the phase status to BKECluster.Status
	Report(msg string, onlyRecord bool) error

	SetCName(name string)

	SetStatus(status confv1beta1.BKEClusterPhaseStatus)

	GetStatus() confv1beta1.BKEClusterPhaseStatus

	SetStartTime(t metav1.Time)

	GetStartTime() metav1.Time

	GetPhaseContext() *PhaseContext

	SetPhaseContext(ctx *PhaseContext)
}
